<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
%>
<html>
<head>
    <meta charset="utf-8">
    <title>修改密码</title>
    <link href="<%=path %>/web/userinfo/css/my_info.css" rel="stylesheet">
</head>
<body>
<div class="my_info_title">修改密码</div>
<div class="my_info_title_3">
    <ul>
        <li id="listClick_1" onClick="listClick(1)">基本资料</li>
        <li id="listClick_3" onClick="listClick(3)">身份认证</li>
        <li id="listClick_4" onClick="listClick(4)" style="border-bottom: 1px solid #C40521; color: #C40521;">修改密码</li>
    </ul>
</div>
<div class="my_info_content">
    <div class="my_info_content_care"></div>
    <form action="<%=path %>/web/userinfo/editPassword" method="post" id="password-form">
    <table class="my_info_content_care_table">
        <tbody>
        <input value="${sessionScope.userinfo.id}" type="hidden" name="id">
        <tr>
            <td width="300" align="right" class="color555">旧密码：</td>
            <td class="color555"><input class="my_info_content_care_table_text" id="oldPassword" required type="password"></td>
        </tr>
        <tr>
            <td align="right" class="color555">新密码：</td>
            <td class="color555"><input class="my_info_content_care_table_text" id="newPassword" name="userpass" required type="password"></td>
        </tr>
        <tr>
            <td align="right" class="color555">确认新密码：</td>
            <td class="color555"><input class="my_info_content_care_table_text" id="newPassword2" type="password" required></td>
        </tr>
        <tr>
            <td align="center" class="color555" colspan="2"><input class="my_info_content_care_table_submit" type="submit" value="确认修改"></td>
        </tr>
        </tbody>
    </table>
    </form>
</div>

</body>
<script src="<%=path %>/web/static/js/modules/jquery-3.3.1.min.js"></script>
<script src="<%=path %>/web/userinfo/js/crowdfunding.js"></script>
<script src="<%=path %>/web/static/layui/layui.all.js"></script>
</html>
<script>
    $(function () {
        var pass1 = false;
        var pass2 = false;

        $("#newPassword").blur(checkPass1)
        $("#newPassword2").blur(checkPass2)

        function checkPass1() {
            var password = $("#newPassword").val();
            if (password.length < 8) {
                layer.msg("密码长度不能少于8位", {offset: '250px'}, {icon: 3})
                pass1 = false;
            } else if (!/^(\w){8,20}$/.test(password)) {
                layer.msg("密码只能包含字母、数字或下划线", {offset: '250px'}, {icon: 3})
                pass1 = false;
            } else {
                pass1 = true;
            }
        }

        function checkPass2() {
            var password = $("#newPassword").val();
            var password2 = $("#newPassword2").val();
            if (password != password2) {
                layer.msg("两次输入的密码不一致", {offset: '250px'}, {icon: 3})
                pass2 = false;
            } else {
                pass2 = true;
            }
        }

        $("#password-form").submit(function () {
            checkPass1();
            checkPass2();
            var result = false;
            if (pass1 && pass2) {
                $.ajax({
                    url: "/GoHome/web/userinfo/checkPass",
                    type: "get",
                    async: false,
                    data: {
                        "userpass": $("#oldPassword").val()
                    },
                    success: function (mes) {
                        if (mes=="true") {
                            result = true;
                        } else {
                            result = false;
                        }
                    }

                })
                if(result){

                    return true;
                }else{
                   layer.msg("原密码输入错误", {offset: '250px'}, {icon: 3});
                   return false;
                }
            } else {
                return false;
            }
        })
    })
</script>